import React, { memo, useContext, useEffect, useState } from 'react'
import { View, Text } from '@tarojs/components'
import Taro from '@tarojs/taro'
import './orders.less'
import { UserContext } from "../../app";
import { Square } from "../../utils";

export default () => {

  const status = Taro.getCurrentInstance().router?.params?.status


  const { user } = useContext(UserContext)
  const [orders, setOrders] = useState([] as any[])

  useEffect(() => {
    if (!user || !user.openid) {
      return
    }
    const fetchData = async () => {
      const resp = await Taro.request({
        url: `${process.env.PREFIX}/order/my`,
        data: { openId: user.openid, status }
      })
      console.log(resp.data)
      setOrders(resp.data.data)
    }
    fetchData()

  }, [user])


  return (
    <View className=''>
      <View>{user.openid}</View>
      <View className='flex-row'>
        <View>待服务</View>
        <View>待发货</View>
        <View>已完成</View>
        <View>全部订单</View>
      </View>
      <View>
        {orders.map(it => {
          return (<View className='flex-row center'>
            <View><Square /></View>
            <View style='width: 100%'>
              <View>[productname]</View>
              <View>{it.status}</View>
              <View>{it.price}</View>
              <View>[查看券码]</View>
            </View>
          </View>)
        })}
      </View>
    </View>
  )
}
